<!--
 * @Author: boyyang
 * @Date: 2022-02-03 13:56:48
 * @LastEditTime: 2022-02-05 13:43:04
 * @LastEditors: boyyang
 * @Description: 
 * @FilePath: \boyyang\src\views\chatRoom\components\chatRoomRightInput.vue
-->

<template>
    <div class="chat-room-input">
        <div class="chat-room-top">
            <div class="chat-room-top-wrapper">
                <custom-upload @onChange="onChange" file-size="7" file-type="image/*">
                    <i class="iconfont icon-tupian1 img-up"></i>
                </custom-upload>
            </div>
        </div>
        <div class="input-wrapper">
            <textarea cols="30" rows="10" maxlength="150" v-model="text"></textarea>
        </div>
        <div class="submit">
            <i class="iconfont icon-dongtai" @click="submit"></i>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { useMessage } from '@/components/message'

interface IChatRoomRightInputProps {
    isClear?: boolean
}

interface IChatRoomRightInputEmits {
    (e: 'submit', str: string): void;
    (e: 'onChange', mes: any): void
}

const message = useMessage()

const props = withDefaults(defineProps<IChatRoomRightInputProps>(), {})
const emits = defineEmits<IChatRoomRightInputEmits>()

const text = ref<string>('')

watch(() => props.isClear, (n_isclear, o_isclear) => {
    if (n_isclear) {
        text.value = ''
    }
})

const submit = () => {
    if (text.value.trim() != '') {
        emits('submit', text.value)
    } else {
        message.error('输入不能为空！')
    }
}

const onChange = (e: any) => {
    emits('onChange', e)
}


</script>

<style scoped lang="scss">
.chat-room-input {
    box-sizing: border-box;
    width: 100%;
    height: 200px;

    background-color: #6b6882;

    position: absolute;
    bottom: 0;

    .chat-room-top {
        box-sizing: border-box;
        width: 100%;
        height: 50px;
        background-color: #d6ecf0;

        .chat-room-top-wrapper {
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            padding: 0 10px;

            .img-up {
                font-size: 26px;
            }
        }
    }

    .input-wrapper {
        height: calc(100% - 50px);
        box-sizing: border-box;
        textarea {
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            resize: none;
            outline: none;
            border: none;
            background-color: #6b6882;

            padding: 10px 15px;

            font-family: "Courier New", Courier, monospace;
            font-weight: bold;
            font-size: 18px;
            color: whitesmoke;
        }
    }

    .submit {
        box-sizing: border-box;
        width: 100%;
        display: flex;
        justify-content: flex-end;
        align-items: center;

        position: absolute;
        bottom: 0;

        padding: 15px;

        i {
            font-size: 25px;
            cursor: pointer;

            &:hover {
                color: whitesmoke;
            }
        }
    }
}

@media screen and (max-width: 1000px) {
    .chat-room-input {
        position: absolute;
        bottom: 0;
        height: 165px;

        .chat-room-top {
            height: 28px;
        }

        .input-wrapper {
            height: 100px;
        }

        .submit {
            padding-top: 0;
            padding-bottom: 6px;
        }
    }
}
</style>